#ifndef _VIDEO_CANVAS_HPP
#define _VIDEO_CANVAS_HPP

#include "../common.hpp"
#include "../math/Vector2.hpp"
#include "Color.hpp"

namespace yep
{
    /**
     * @brief A place to draw on.
     *
     * It is like a blank board. You draw anything you want to and you clear() when you get tired.
     **/
    class Canvas
    {
    public:
        virtual ~Canvas();

        /**
         * @brief Returns the surface.
         *
         * Avoid calling this, because it breaks the abstraction, prefer using the other methods.
         **/
        SDL_Surface *getSurface() const
        {
            return surface;
        }

        /**
         * @brief Returns the canvas width
         **/
        unsigned getWidth() const
        {
            return surface->w;
        }

        /**
         * @brief Returns the canvas height
         **/
        unsigned getHeight() const
        {
            return surface->h;
        }

        /**
         * @brief Returns the size of the
         */
        Vector2 getSize() const
        {
        	return {(double)getWidth(), (double)getHeight()};
        }

        /**
         * @brief Return the color of the specified pixel
         **/
        Color getPixel(const Vector2 &position) const;

        /**
         * @brief Changes the color of the specified pixel
         **/
        void setPixel(const Vector2 &position, const Color &color);

        /**
         * @brief Puts the pixel on specified position
         **/
        void putPixel(const Vector2 &position, const Color &color);

        /**
         * @brief paints the screen with the given color.
         **/
        void clear(const Color &color);

        /**
         * @brief Writes on screen.
         **/
        void drawText(const Vector2 &position, const Color &color, const string &text);

        /**
         * @brief Draw a Areaangle
         **/
        void drawRectangle(const Vector2 &topLeft, const Vector2 &size, const Color &color);

        /**
         * @brief Fill a Areaangle
         **/
        void fillRectangle(const Vector2 &topLeft, const Vector2 &size, const Color &color);

        /**
         * @brief Sets a section of the canvas to draw, locking the rest
         */
        void setClipArea(const Vector2 &topLeft, const Vector2 &size);

        /**
         * @brief Sets a section of the canvas to draw, locking the rest
         */
        void setClipArea(const Vector2 &topLeft);

        /**
         * @brief Clear the DrawArea
         */
        void clearClipArea();
    protected:

        /**
         * @brief Create a canvas with given surface.
         *
         * @param surface The surface;
         * @param freeAtEnd if it has to free the surface.
         **/
        Canvas(SDL_Surface *surface_, bool freeAtEnd_);

        SDL_Surface *surface;
        bool owner;
    };

}

#endif // _VIDEO_CANVAS_HPP

